package mysql

import (
	"gorm.io/gorm"
	"me/123/common/global"
	"me/123/common/model"
)

func QueryUserCouponsInfoByUid(uid int64) (result *model.UserCoupons, err error) {
	err = global.DB.Model(&model.UserCoupons{}).Where("uid = ?", uid).Limit(1).Find(&result).Error
	return
}

func CreateOrder(m *model.Orders) error {
	return global.DB.Create(m).Error
}

func QueryOrderInfo(sn string) (result *model.Orders, err error) {
	err = global.DB.Model(&model.Orders{}).Where("order_number = ?", sn).Limit(1).Find(&result).Error
	return
}

func UpdateOrderStatus(sn string, status int64, tx *gorm.DB) error {
	return tx.Model(&model.Orders{}).Where("order_number = ?", sn).Update("order_status", status).Error
}
